package cn.school.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloServlet extends javax.servlet.http.HttpServlet {
    public HelloServlet(){
        System.out.println("hello servlet constructor");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("hello servlet 初始化了");
        String config = super.getInitParameter("config");

    }

    @Override
    public void destroy() {
        System.out.println("hello servlet 清理资源了。。。");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这个是service开始");
        super.service(req, resp);
        System.out.println("service结束");
    }

    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>");
        out.println("We change lives!");
        out.println("</h1>");
        out.println("<h1>");
        out.println("This is a post request!"+new java.util.Date());
        out.println("</h1>");
        out.println("</body>");
        out.println("</html>");
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>");
        out.println("We change lives教育改变生活!");
        out.println("</h1>");
        out.println("<h1>");
        out.println("This is a get request!"+new java.util.Date());
        out.println("</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}
